﻿using System;

namespace SelectionSort
{
    class SelectionSort
    {
        static void PrintArray(int[] array)
        {
            Console.Write("{ ");
            for (int index = 0, length = array.Length - 1; index < length; index++)
            {
                Console.Write("{0}, ", array[index]);
            }
            Console.WriteLine("{0} }}", array[array.Length - 1]);
        }

        static void Sort(int[] array)
        {
            for (int i = 0, length = array.Length - 1; i <= length; i++)
            {
                int minValueIndex = i;
                for (int j = i; j <= length; j++)
                {
                    if (array[minValueIndex] > array[j])
                    {
                        minValueIndex = j;
                    }
                }
                int tmp = array[i];
                array[i] = array[minValueIndex];
                array[minValueIndex] = tmp;
            }
        }

        static void Main()
        {
            int arrayLength;
            int[] numbers;

            Console.Write("Please enter the length of your array: ");
            arrayLength = int.Parse(Console.ReadLine());
            numbers = new int[arrayLength];
            for (int index = 0; index < arrayLength; index++)
            {
                Console.Write("Index [{0}]: ", index);
                numbers[index] = int.Parse(Console.ReadLine());
            }

            Sort(numbers);
            PrintArray(numbers);
        }
    }
}
